/*     */ package com.cr.quartz.util;
/*     */ 
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.cr.common.utils.spring.SpringUtils;
/*     */ import com.cr.quartz.domain.SysJob;
/*     */ import java.lang.reflect.InvocationTargetException;
/*     */ import java.lang.reflect.Method;
/*     */ import java.util.LinkedList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class JobInvokeUtil {
/*     */   public static void invokeMethod(SysJob sysJob) throws Exception {
/*  25 */     String invokeTarget = sysJob.getInvokeTarget();
/*  26 */     String beanName = getBeanName(invokeTarget);
/*  27 */     String methodName = getMethodName(invokeTarget);
/*  28 */     List<Object[]> methodParams = getMethodParams(invokeTarget);
/*  30 */     if (!isValidClassName(beanName)) {
/*  32 */       Object bean = SpringUtils.getBean(beanName);
/*  33 */       invokeMethod(bean, methodName, methodParams);
/*     */     } else {
/*  37 */       Object bean = Class.forName(beanName).newInstance();
/*  38 */       invokeMethod(bean, methodName, methodParams);
/*     */     } 
/*     */   }
/*     */   
/*     */   private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
/*  53 */     if (MyStringUtils.isNotNull(methodParams) && methodParams.size() > 0) {
/*  55 */       Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams));
/*  56 */       method.invoke(bean, getMethodParamsValue(methodParams));
/*     */     } else {
/*  60 */       Method method = bean.getClass().getDeclaredMethod(methodName, new Class[0]);
/*  61 */       method.invoke(bean, new Object[0]);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static boolean isValidClassName(String invokeTarget) {
/*  73 */     return (MyStringUtils.countMatches(invokeTarget, ".") > 1);
/*     */   }
/*     */   
/*     */   public static String getBeanName(String invokeTarget) {
/*  84 */     String beanName = MyStringUtils.substringBefore(invokeTarget, "(");
/*  85 */     return MyStringUtils.substringBeforeLast(beanName, ".");
/*     */   }
/*     */   
/*     */   public static String getMethodName(String invokeTarget) {
/*  96 */     String methodName = MyStringUtils.substringBefore(invokeTarget, "(");
/*  97 */     return MyStringUtils.substringAfterLast(methodName, ".");
/*     */   }
/*     */   
/*     */   public static List<Object[]> getMethodParams(String invokeTarget) {
/* 108 */     String methodStr = MyStringUtils.substringBetween(invokeTarget, "(", ")");
/* 109 */     if (MyStringUtils.isEmpty(methodStr))
/* 111 */       return null; 
/* 113 */     String[] methodParams = methodStr.split(",");
/* 114 */     List<Object[]> classs = new LinkedList();
/* 115 */     for (int i = 0; i < methodParams.length; i++) {
/* 117 */       String str = MyStringUtils.trimToEmpty(methodParams[i]);
/* 119 */       if (MyStringUtils.contains(str, "'")) {
/* 121 */         classs.add(new Object[] { MyStringUtils.replace(str, "'", ""), String.class });
/* 124 */       } else if (MyStringUtils.equals(str, "true") || MyStringUtils.equalsIgnoreCase(str, "false")) {
/* 126 */         classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
/* 129 */       } else if (MyStringUtils.containsIgnoreCase(str, "L")) {
/* 131 */         classs.add(new Object[] { Long.valueOf(MyStringUtils.replaceIgnoreCase(str, "L", "")), Long.class });
/* 134 */       } else if (MyStringUtils.containsIgnoreCase(str, "D")) {
/* 136 */         classs.add(new Object[] { Double.valueOf(MyStringUtils.replaceIgnoreCase(str, "D", "")), Double.class });
/*     */       } else {
/* 141 */         classs.add(new Object[] { Integer.valueOf(str), Integer.class });
/*     */       } 
/*     */     } 
/* 144 */     return classs;
/*     */   }
/*     */   
/*     */   public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) {
/* 155 */     Class<?>[] classs = new Class[methodParams.size()];
/* 156 */     int index = 0;
/* 157 */     for (Object[] os : methodParams) {
/* 159 */       classs[index] = (Class)os[1];
/* 160 */       index++;
/*     */     } 
/* 162 */     return classs;
/*     */   }
/*     */   
/*     */   public static Object[] getMethodParamsValue(List<Object[]> methodParams) {
/* 173 */     Object[] classs = new Object[methodParams.size()];
/* 174 */     int index = 0;
/* 175 */     for (Object[] os : methodParams) {
/* 177 */       classs[index] = os[0];
/* 178 */       index++;
/*     */     } 
/* 180 */     return classs;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-quartz-4.7.0.jar!\com\cr\quart\\util\JobInvokeUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */